<template>
  <div class="film-item">
    <div class="film-item-left">
      <img class="film-item-left-poster" :src="item.poster" />
    </div>
    <div class="film-item-right">
      <div class="film-info" @click="goToFilmInfo(item.filmId)">
        <div class="film-name">
          {{ item.name }}
          <span class="film-type">{{ item.filmType.name }}</span>
        </div>
        <div
          class="film-grade"
          :style="{ visibility: item.grade ? 'visible' : 'hidden' }"
        >
          观众评分
          <span class="film-grade-span">{{ item.grade }}</span>
        </div>
        <div class="film-actors">
          <span class="film-actors-span">主演:{{ actorsStr }}</span>
        </div>
        <div class="film-more">
          <template v-if="isHot">
            <span class="film-more-place">{{ item.nation }}</span> |
            <span class="film-more-time">{{ item.runtime }}分钟</span>
          </template>
          <template v-else>
            <span class="film-more-place">上映日期：{{ premiereAt }}</span>
          </template>
        </div>
      </div>
      <div class="film-handle">
        <template v-if="isHot">
          <van-button class="buy" @click="ticket()"> 购票 </van-button>
        </template>
        <template v-else>
          <van-button class="preoder" v-if="item.isPresale"> 预购</van-button>
        </template>
      </div>
    </div>
  </div>
</template>

<script>
export default { name: "film-item" };
</script>

<script setup>
import { computed } from "@vue/reactivity";
import dayjs from "dayjs";
import router from "../router";

const props = defineProps({
  item: {
    type: Object,
  },
  isHot: {
    type: Boolean,
  },
});
const actorsStr = computed(() => {
  if (props.item.actors) {
    return props.item.actors.map((item) => item.name).join(" ");
  } else {
    return "暂无主演";
  }
});
const premiereAt = computed(() => {
  const msTime = props.item.premiereAt * 1000;
  const day = dayjs(msTime);
  const numberWeek = {
    0: "周天",
    1: "周一",
    2: "周二",
    3: "周三",
    4: "周四",
    5: "周五",
    6: "周六",
  };
  return numberWeek[day.format("d")] + " " + day.format("MM月DD日");
});

function goToFilmInfo(filmId) {
  router.push(`/film/${filmId}`);
  console.log(filmId);
}

function ticket() {
  console.log(ticket);
}
</script>

<style lang="scss" scoped>
.film-item {
  position: relative;
  display: flex;
  padding: 15px;
  &-left {
    height: 94px;
    &-poster {
      width: 66px;
      height: 100%;
    }
  }
  &-right {
    flex: 1;
    display: flex;
    overflow: hidden;
    // align-items: center;
  }
  .film-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 0 10px;
    overflow: hidden;
  }
  .film-name {
    font-size: 16px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .film-grade,
  .film-actors,
  .film-more {
    font-size: 14px;
    color: #797d82;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .film-handle {
    line-height: 94px;
    width: 50px;
  }
  .film-type {
    font-size: 9px;
    color: #fff;
    background-color: #d2d6dc;
    height: 14px;
    line-height: 14px;
    padding: 0 2px;
    border-radius: 2px;
    display: inline-block;
    //电影类型溢出应该还有三个点（未实现）
    // overflow: hidden;
    // text-overflow: ellipsis;
    // white-space: nowrap;
    position: absolute;
    margin-left: 5px;
  }
  .film-grade-span {
    color: #ffb232;
  }
  .film-actors {
    width: 100%;
    min-width: 0;
  }
  .buy {
    padding: 0;
    width: 50px;
    height: 26px;
    font-size: 12px;
    color: #ff5f16;
    border-color: #ff5f16;
  }
  .preoder {
    padding: 0;
    width: 50px;
    height: 26px;
    font-size: 12px;
    color: #ffb232;
    border-color: #ffb232;
  }
}
</style>
